<template>
	<view class="content">
		<view class="list" v-if="isLoad">
			<my-item 
			   v-for="item of list"
			   :key="item['id']"
			   :data="item"
			/>
		</view>
		<data-empty v-if="!list.length" />
	</view>
</template>

<script>
	import item from './item.vue'
	export default {
		components: {
			'my-item': item
		},
		data (){
			return {
				isLoad: false,
				list: []
			}
		},
		onShow (){
			// #ifdef MP-WEIXIN
			const result = this.$checkLogin()
			if(!result) return false
			// #endif
			
			const token = this.$store.state.access_token
			token && this.getMsgList(token)
			this.isLoad = true
		},
		methods: {
			// 获取消息
			getMsgList (token){
				this.$request.get('/messages?accesstoken=' + token)
					.then(result => {
						if(result.success){
							this.list = [...result['data']['has_read_messages'], ...result['data']['hasnot_read_messages']]
						}
						this.isLoad = true
					})
			}
		}
	}
</script>
<style lang="scss">
	.content {
		background-color: #fff;
	}
</style>
